module.exports = {
    data:{
        wiiCounter:{
            data: {
                isMin: false,
                isMax: false,
                numberUnit:1,
                countNumber:1,
                minNumber:1,
                maxNumber:10000000
            }
        }
    },
    wiiCounterTap:function(evt){
        var prefix = evt.target.dataset.prefix;
        console.log(prefix)
        var isMax,isMin,nowNumber,numberUnit,minNumber,maxNumber;
        var numberType = evt.target.dataset.type;
        var prefixArr = [];
        var data = this.data;
        if(!!prefix){
            prefixArr = prefix.split('.');
            var prefixLength = prefixArr.length;
            for(var i = 0;i<prefixLength;i++){
                data = data[prefixArr[i]];
            }
            prefix = prefix+'.';
           
        }else{
            prefix = '';
        }
        nowNumber = data['wiiCounter']['data']['countNumber'];
        numberUnit = data['wiiCounter']['data']['numberUnit'];
        minNumber = data['wiiCounter']['data']['minNumber']; //最小值
        maxNumber = data['wiiCounter']['data']['maxNumber']; //最大值
        
        
        if(numberType == 'subtract'){
            nowNumber = nowNumber - numberUnit;
        }else if(numberType == 'add'){
            nowNumber = nowNumber + numberUnit;
        }

        if(minNumber <= nowNumber && nowNumber <= maxNumber){
            var keyCountNumber = prefix+'wiiCounter.data.countNumber';
            this.setData({
                [keyCountNumber]:nowNumber
            });
        }
        var keyIsMin = prefix+'wiiCounter.data.isMin';
        var keyIsMax = prefix+'wiiCounter.data.isMax';
        var keyMinNumber = prefix+'wiiCounter.data.minNumber';
        var keyMaxNumber = prefix+'wiiCounter.data.maxNumber';
        if(nowNumber < minNumber + numberUnit){
            isMin = true;
            isMax = false;
            this.setData({
                [keyIsMin]:isMin,
                [keyIsMax]:isMax
            });
            if(nowNumber < minNumber){
                return false;
            }
        }else if(nowNumber > maxNumber - numberUnit){
            isMax = true;
            isMin = false;
            this.setData({
                [keyIsMin]:isMin,
                [keyIsMax]:isMax
            });
            if(nowNumber > maxNumber){
                return false;
            }
        }else{
            this.setData({
                [keyIsMin]:false,
                [keyIsMax]:false,
                [keyMinNumber]:minNumber,
                [keyMaxNumber]:maxNumber
            });
        }
        this.callback.call(this,'counterTap',nowNumber);
    }
}